package com.zh.note.demo.juc;

import java.util.concurrent.*;

/**
 * @Author: zhanghuan
 * @date: 2023/6/23 18:36
 * @description: create it
 */
public class ThreadDemo {
    private static final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
            Runtime.getRuntime().availableProcessors(), // 获取当前处理器的核心
            Runtime.getRuntime().availableProcessors() * 2,
            200,
            TimeUnit.MICROSECONDS,
            new LinkedBlockingDeque<>(1000),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.DiscardOldestPolicy());

    public static void main(String[] args) {
        /**
         * shutdown后线程池中的任务会怎样
         */
        // threadPoolExecutor.execute(() -> {
        //     System.out.println(Thread.currentThread().getName());
        // });
        // threadPoolExecutor.shutdown();

        /**
         * 线程池捕获异常
         */
        // Future<?> submit = threadPoolExecutor.submit(() -> {
        //     System.out.println(Thread.currentThread().getName() + 10 / 0);
        // });
        // try {
        //     submit.get();
        // } catch (Exception e) {
        //     System.out.println(e);
        // }


    }
}
